//
//  STMeHeaderView.m
//  CuiBoStore
//
//  Created by 崔博 on 16/12/1.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "STMeHeaderView.h"
#import "STLoginController.h"
@interface STMeHeaderView ()
@property (nonatomic, strong) UIImageView *headerBackImageView;
@property (nonatomic, strong) UIButton *loginBtn;
@property (nonatomic, strong) UIButton *regisBtn;
@end

@implementation STMeHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        
        [self addSubviews];
    }
    return self;
}
#pragma mark - methoed
// 添加子试图
- (void)addSubviews{
    
    [self addSubview:self.headerBackImageView];
    [self addSubview:self.loginBtn];
    [self addSubview:self.regisBtn];
    
    [_headerBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerBackImageView.mas_centerX).offset(60);
        make.centerY.equalTo(self.headerBackImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
    
    [_regisBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerBackImageView.mas_centerX).offset(-60);
        make.centerY.equalTo(self.headerBackImageView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
    
}
#pragma mark - event
- (void)login:(UIButton *)sender{
    UIViewController *regisVC;
    if (sender.tag == -1) {
        regisVC = [[STLoginController alloc] initWithVCStyle:LoginStyle];
    }else
    {
        regisVC = [[STLoginController alloc] initWithVCStyle:RegisStyle];
    }
     [self.viewController.navigationController pushViewController:regisVC animated:YES];
}

#pragma mark - lazy
- (UIImageView *)headerBackImageView
{
    if (!_headerBackImageView) {
        _headerBackImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的背景"]];
    }
    return _headerBackImageView;
}
- (UIButton *)loginBtn
{
    if (!_loginBtn) {
        _loginBtn = [STUIKitTools buttonTitle:@"登入" font:15 action:@selector(login:) titleColor:[UIColor whiteColor] target:self];
        _loginBtn.tag = -1;
    }
    return _loginBtn;
}
- (UIButton *)regisBtn
{
    if (!_regisBtn) {
        _regisBtn = [STUIKitTools buttonTitle:@"注册" font:15 action:@selector(login:) titleColor:[UIColor whiteColor] target:self];
    }
    return _regisBtn;
}

@end
